<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript">
    $().ready(function() { 
        view(1);  
        /* 조회버튼 */
        $("#btnSearch").bind("click",function(){       
            view(1);
        }); 

        $("#cancelBtn").bind("click",function(){       
            self.close();
        });  

        $("#confirmBtn").bind("click",function(){   
            var custName = $("#custNameTmp").val();
            var custCode = $("#custCodeTmp").val();
            var addr1    = $("#addr1Tmp").val();
            var addr2    = $("#addr2Tmp").val();
            var tel      = $("#telTmp").val();
            var fax      = $("#faxTmp").val();

            if(custCode==null   || custCode=="") {   alert("Row selected!!"); return false; }

            opener.customerPopValue(custCode, custName, addr1, addr2, tel, fax);
            self.close();
        });
        
    });

    function view(page){
        $.post(
                '/getCustomerPopView.json', {                      
                paging : page,//odrNo,
                listScale : "5",
               // custDiv : $("#custDiv").val(),
                custName : $("#custName").val(),
                messrsCode : $("#messrsCode").val(),
                custCode : $("#custCode").val(),
                customer : $("#customer").val()
               },
            function(data) {
                //$("#customerDetail").remove();
                //reSetValidete(); //벨류데이션 초기화
                searchDataMaping(data);    //DATA맵핑 
            });
    }
    
    /* searchData 맵핑 */
    function searchDataMaping(data){
           
        var contents = "";
        var cHeader = "<tr>"
        	+"<th width='17%'>Div</th>"
        	+"<th width='13%'>Code</th>"
        	+"<th width='25%'>Name</th>"
        	+"<th width='20%'>Nation</th>"
        	+"<th width='25%'>Messrs</th>"
        	+"</tr>";
        if(data.resultList.length == 0){
            contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
            $("#customerDetail").html(cHeader+contents);
            
        }else{
        	 $.each(data.resultList, function(index){  // List로 받아온값 (여러건)  
                 contents += "<tr style='cursor:pointer' onclick='rowSelect(this, \""+this.custCode+"\", \""+this.custName+"\", \""+this.addr1+"\"  , \""+this.addr2+"\" , \""+this.tel+"\" , \""+this.fax+"\" );  '>"
                     +"<td align='center'>"+this.custDivName+"</td>"
                     +"<td align='center'>"+this.custCode+"</td>"
                     +"<td align='left' class='boSub'>"+this.custName+"</td>"
                     +"<td align='left' class='boSub'>"+this.nation+"</td>"
                     +"<td align='left' class='boSub'>"+this.messrsName+"</td>"
                     +"</tr>";
                  
              });
        }
        
        var totalPage = Math.ceil(parseInt(data.customeCount)/parseInt(5));        
        $("#spanCount").empty().html("Total : "+data.customeCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);                    
        $("#page").empty().html(data.pageSplit);
        
        $("#customerDetail").html(cHeader+contents);  // 조회 값 뿌리기
    }   

    function ajaxPageSplit(num) {
        $("#pageNum").val(num);
        view(num);
    }

    function rowSelect(obj, custCode, custName, addr1, addr2, tel, fax){
        $("#custNameTmp").val(custName);
        $("#custCodeTmp").val(custCode);
        $("#addr1Tmp").val(addr1);
        $("#addr2Tmp").val(addr2);
        $("#telTmp").val(tel);
        $("#faxTmp").val(fax);
        $("#customerDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
		document.ondblclick=dblclick;
    }

	function dblclick(){
		$("#confirmBtn").click(); 
	}
</script>
</head>
<body>
<input type="hidden" id="customer" value="<c:out value="${customer}" />" />
<input type="hidden" id="messrsCode" value="<c:out value="${messrsCode}" />" />
<div class="wrapP">
    <div class="pagetitle">
        <h1>Customer</h1>
    </div>
    <div>
        <table class="TableST">
            <tr>
                <th>Code</th>
                <td>
                    <input type="text" class="inST30" name="custCode" id="custCode"/>
                </td>
            </tr>
            <tr>
                <th>Name</th>
                <td>
                    <input type="text" class="inST30" name="custName" id="custName"/>
                </td>
            </tr>
        </table>
        <div class="bo_btnS">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </div>
        <br/><br/><br/><br/>
        <ul>
            <li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
                <table class="TableST4" id="customerDetail">
                    <!-- tr>
                        <th width="90px">Div</th>
                        <th width="90px">Code</th>
                        <th width="90px">Name</th>
                        <th width="50px">Nation</th>
                    </tr>
                    <span id="customerDetail">
                        <tr>
                           <td colspan="4"></td>    
                        </tr>
                    </span-->                    
                </table>
            </li>
        </ul>
    </div>
    <!--<div class="padeNum">
    <a href="#"><img src="images/web/icon_navi_01.gif" /></a>1.2.3.4.5.6.7<a href="#"><img src="images/web/icon_navi_02.gif" /></a>
    </div>
    -->
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <div class="bo_btn">
        <ul class="btnst"><li class="a"><a href="#" id="confirmBtn" >CONFIRM</a></li></ul>
        <ul class="btnst"><li class="a"><a href="#" id="cancelBtn" >CANCEL</a></li></ul>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
    <input type="hidden" name="custCodeTmp" id="custCodeTmp"/>
    <input type="hidden" name="custNameTmp" id="custNameTmp"/>
    <input type="hidden" name="addr1Tmp" id="addr1Tmp"/>
    <input type="hidden" name="addr2Tmp" id="addr2Tmp"/>
    <input type="hidden" name="telTmp" id="telTmp"/>
    <input type="hidden" name="faxTmp" id="faxTmp"/>
</div>
</body>
</html>